open(BUFF,"gunzip -c ../ALL.chr8.20110521.b37p0.snps.markers.gz |") or die "no file exists\n";
while(<BUFF>)
{
	chomp($_);
	@array = split(" ",$_);	
	$hash{$array[0]} = "$array[2] $array[3]";
	#print $_."\n";
}
open(BUFF,"UCSF_Imputation_new_selected.bim") or die "no file exists\n";
open(WRBUFF,">flip_snps_list_UCSF") or die "not able to write UCSF\n";
while(<BUFF>)
{
        chomp($_);
        @array = split("\t",$_);
	#print $array[1]."\n";
	if(exists($hash{$array[1]}))
	{
		@cmp1 = split(" ",$hash{$array[1]});
		if($_ =~ m/$cmp1[0]/ || $_ =~ m/$cmp1[1]/)
		{		
			
		}
		else
		{
			print WRBUFF $array[1]."\n";
		}
	}
}
#flip manually 3 amibious snps from hugues
#print WRBUFF "130726970\nrs4367505\nrs6993442\n";
system("plink --bfile UCSF_Imputation_new_selected --flip flip_snps_list_UCSF --make-bed --out UCSF_Tom_Hugues_selected_fliped_1000g");
open(BUFF,"Mayo_Imputation_new_selected.bim") or die "no file exists\n";
open(WRBUFF,">flip_snps_list_Mayo") or die "not able to write Mayo\n";
while(<BUFF>)
{
        chomp($_);
        @array = split("\t",$_);
        #print $array[1]."\n";
        if(exists($hash{$array[1]}))
        {
                @cmp1 = split(" ",$hash{$array[1]});
                if($_ =~ m/$cmp1[0]/ || $_ =~ m/$cmp1[1]/)
                {

                }
                else
                {
                        print WRBUFF $array[1]."\n";
                }
        }
}
system("plink --bfile Mayo_Imputation_new_selected --flip  flip_snps_list_Mayo --make-bed --out Mayo_Tom_Hugues_selected_fliped_1000g");
system("plink --bfile Mayo_Tom_Hugues_selected_fliped_1000g --bmerge UCSF_Tom_Hugues_selected_fliped_1000g.bed UCSF_Tom_Hugues_selected_fliped_1000g.bim UCSF_Tom_Hugues_selected_fliped_1000g.fam --recode --transpose --out merged");
